﻿
namespace HSS.Xaml.UI.Data
{
	#region Using Directives
	using System;
	using System.Collections;
	using System.Windows.Data;
	#endregion

	#region ListCountBooleanValueConverter
	/// <summary>
	/// If the provided value implements IList, and has a count greater than the provided parameter value or 0 when null, returns true; otherwise false.
	/// </summary>
	public class ListCountBooleanValueConverter : IValueConverter
	{
		/// <summary>
		/// If the provided value implements IList, and has a count greater than to the provided parameter value or 0 when null, returns true; otherwise false.
		/// </summary>
		/// <param name="value">An object which implements <see cref="IList"/>.</param>
		/// <param name="targetType">Not used.</param>
		/// <param name="parameter">The optional minimum list count.</param>
		/// <param name="culture">Not used.</param>
		/// <returns>true if the list has a count greater than the provided parameter or zero if no parameter was provided; otherwise false.</returns>
		public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			if (value != null)
			{
				var list = value as IList;
				if (list != null)
				{
					if (null == parameter)
						parameter = "0";
					int minCount = 0;
					if (int.TryParse(parameter.ToString(), out minCount))
						return (list.Count > minCount) ? true : false;
					return (list.Count > 0) ? true : false;
				}

			}
			return false;
		}
		/// <summary>
		/// NotImplementedException
		/// </summary>
		/// <param name="value">Not used.</param>
		/// <param name="targetType">Not used.</param>
		/// <param name="parameter">Not used.</param>
		/// <param name="culture">Not used.</param>
		/// <returns>NotImplementedException</returns>
		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			throw new NotImplementedException();
		}
	}
	#endregion
}